home *** CD-ROM | disk | FTP | other *** search
/ Best of Shareware / Best of PC Windows Shareware 1.0 - Wayzata Technology (7111) (1993).iso / mac / ZIPPED / WINDOWS / PRINTERS / NODEE1A.ZIP / NODCHILD.CPP < prev    next >
C/C++ Source or Header  |  1991-09-15  |  7KB  |  348 lines

  1. /*
  2. NODCHILD.CPP
  3.  
  4. code for child windows for the NoD program
  5.  
  6. */
  7.  
  8.     #ifndef __WINDOWS_H
  9.         #include <Windows.h>
  10.     #endif  // __WINDOWS_H
  11.  
  12.     #ifndef __NODCHILD_H
  13.         #include "Nodchild.h"
  14.     #endif
  15.  
  16.     #ifndef __STRING_H
  17.         #include <string.h>
  18.     #endif
  19.  
  20.     #ifndef __NOD1_H
  21.         #include "nod1.h"
  22.     #endif
  23.  
  24.  
  25.  
  26.  
  27. /*------------------------------------------------ Child Classes
  28.  
  29. */
  30.  
  31.     void DBox::create(HWND hA)
  32.     {
  33.  
  34.         HDC hdc;
  35.         TEXTMETRIC tm;
  36.         int cxChar,cyChar;
  37.         char *text="ICK!";
  38.  
  39.         hParent=hA;
  40.  
  41.         hdc=GetDC(hParent);
  42.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  43.         GetTextMetrics(hdc,&tm);
  44.         cxChar=tm.tmAveCharWidth;
  45.         cyChar=tm.tmHeight+tm.tmExternalLeading;
  46.         ReleaseDC(hParent,hdc);
  47.  
  48.         hwndChild=CreateWindow
  49.             ("button",text,WS_CHILD|WS_VISIBLE|SS_CENTER,
  50.             XDBOX,YDBOX,CXDBOX,CYDBOX,
  51.             hParent,MYCW_ICKBUTTON,WinBase::hInst,NULL);
  52.         set(FALSE);
  53.     }
  54.  
  55.     void DBox::set(BOOL a=TRUE)
  56.     {
  57.         if (a)
  58.         {
  59.             ShowWindow(hwndChild,SW_SHOWNORMAL);
  60.             EnableWindow(hwndChild,TRUE);
  61.         }
  62.         else
  63.         {
  64.             ShowWindow(hwndChild,SW_HIDE);
  65.             EnableWindow(hwndChild,FALSE);
  66.         }
  67.  
  68.     }
  69.  
  70. /*-----------------------------------------------
  71. */
  72.  
  73.  
  74.     void GoButton::create(HWND hA)
  75.     {
  76.  
  77.         HDC hdc;
  78.         TEXTMETRIC tm;
  79.         int cxChar,cyChar;
  80.         text="Take It Out";
  81.  
  82.         hParent=hA;
  83.  
  84.         hdc=GetDC(hParent);
  85.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  86.         GetTextMetrics(hdc,&tm);
  87.         cxChar=tm.tmAveCharWidth;
  88.         cyChar=tm.tmHeight+tm.tmExternalLeading;
  89.         ReleaseDC(hParent,hdc);
  90.  
  91.         hwndChild=CreateWindow
  92.             ("button",text,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
  93.             XGOBUTTON,YGOBUTTON,CXGOBUTTON,CYGOBUTTON,
  94.             hParent,MYCW_GOBUTTON,WinBase::hInst,NULL);
  95.     }
  96.  
  97. /*------------------------------------------------------------*/
  98.  
  99.  
  100.     void FirstLine::create(HWND hA)
  101.     {
  102.         HDC hdc;
  103.         TEXTMETRIC tm;
  104.         int cxChar,cyChar;
  105.         text="nothing yet";
  106.  
  107.         hParent=hA;
  108.  
  109.         hdc=GetDC(hParent);
  110.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  111.         GetTextMetrics(hdc,&tm);
  112.         cxChar=tm.tmAveCharWidth;
  113.         cyChar=tm.tmHeight+tm.tmExternalLeading;
  114.         ReleaseDC(hParent,hdc);
  115.  
  116.         hwndChild=CreateWindow
  117.             ("static",text,WS_CHILDWINDOW|WS_VISIBLE|SS_LEFT,
  118.             XFILEFIELD,YFILEFIELD,CXFILEFIELD,CYFILEFIELD,
  119.             hParent,MYCW_FIRSTLINE,WinBase::hInst,NULL);
  120.     }
  121.  
  122.     void FirstLine::set(char* a)
  123.     {
  124.         SetWindowText(hwndChild,(LPSTR) a);
  125.     }
  126.  
  127. /*--------------------------------------------------------------------*/
  128.  
  129.     void FileList::create(HWND hA)
  130.     {
  131.         HDC hdc;
  132.         TEXTMETRIC tm;
  133.         int cxChar,cyChar;
  134.  
  135.         hParent=hA;
  136.         if (strlen(szMask)==0)
  137.             mask("*.*");
  138.  
  139.         hdc=GetDC(hParent);
  140.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  141.         GetTextMetrics(hdc,&tm);
  142.         cxChar=tm.tmAveCharWidth;
  143.         cyChar=tm.tmHeight;
  144.         ReleaseDC(hParent,hdc);
  145.  
  146.         hwndChild=CreateWindow
  147.             ("listbox",NULL,WS_CHILDWINDOW|WS_VISIBLE|LBS_STANDARD,
  148.             XFILELIST,YFILELIST,CXFILELIST,CYFILELIST,
  149.             hParent,MYCW_FILELIST,WinBase::hInst,NULL);
  150.  
  151.         reset();
  152.  
  153.         bValidFile=FALSE;
  154.     }
  155.  
  156.     DWORD FileList::send(WORD msg,WORD wParam,long lParam)
  157.     {
  158.         return SendMessage(hwndChild,msg,wParam,lParam);
  159.     }
  160.  
  161.     void FileList::mask(char *a)
  162.     {
  163.         strcpy(szMask,a);
  164.     }
  165.  
  166.  
  167.     BOOL FileList::fileClick(void)
  168.     {
  169.         int index;
  170.         char szBuffer[MAXPATH];
  171.         OFSTRUCT ofs;
  172.  
  173.         if (LB_ERR ==    (index= (WORD) send(LB_GETCURSEL,0,0L)) )
  174.                 return FALSE;
  175.  
  176.         send(LB_GETTEXT,index,(LONG) (char far *) szBuffer);
  177.  
  178.         bValidFile =
  179.             ( OpenFile(szBuffer,&ofs,OF_EXIST|OF_READ) != -1 ? TRUE : FALSE ) ;
  180.         if (bValidFile)
  181.             strcpy(szFileName,(char *)ofs.szPathName);
  182.  
  183.         return TRUE;
  184.     }
  185.  
  186.  
  187.     BOOL FileList::validFile(void)
  188.     {
  189.         return bValidFile;
  190.     }
  191.  
  192.     char* FileList::getFile(void)
  193.     {
  194.         return szFileName;
  195.     }
  196.  
  197.     void FileList::reset(void)
  198.     {
  199.         send(LB_RESETCONTENT,0,0L);
  200.         send(LB_DIR,0x0,(LONG)(LPSTR) szMask);
  201.     }
  202.  
  203. /*--------------------------------------------------------------------
  204. DirList code
  205. */
  206.  
  207.     void DirList::create(HWND hA)
  208.     {
  209.         HDC hdc;
  210.         TEXTMETRIC tm;
  211.         char szTemp[MAXPATH];
  212.         int cxChar,cyChar;
  213.  
  214.         hParent=hA;
  215.  
  216.         hdc=GetDC(hParent);
  217.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  218.         GetTextMetrics(hdc,&tm);
  219.         cxChar=tm.tmAveCharWidth;
  220.         cyChar=tm.tmHeight;
  221.         ReleaseDC(hParent,hdc);
  222.  
  223.         hwndChild=CreateWindow
  224.             ("listbox",NULL,WS_CHILDWINDOW|WS_VISIBLE|LBS_STANDARD,
  225.             XDIRLIST,YDIRLIST,CXDIRLIST,CYDIRLIST,
  226.             hParent,MYCW_DIRLIST,WinBase::hInst,NULL);
  227.  
  228.         reset();
  229.  
  230.  
  231. /* This object creates this box and keeps the handle.
  232. Control is not allowed outside the object. */
  233.  
  234.         hDirField=CreateWindow
  235.             ("static"," ",WS_CHILDWINDOW|WS_VISIBLE|SS_LEFT,
  236.             XDIRFIELD,YDIRFIELD,CXDIRFIELD,CYDIRFIELD,
  237.             hParent,MYCW_DIRFIELD,WinBase::hInst,NULL);
  238.  
  239.         getcwd(szDirName,MAXPATH);
  240.  
  241.         if (strlen(szDirName) > WIDTHDIRFIELD)
  242.         {
  243.             strcpy(szTemp,szDirName);
  244.             do
  245.                 strcpy(szTemp,(char *)strchr(szTemp,'\\')+1);
  246.             while (strlen(szTemp)>WIDTHDIRFIELD-4);
  247.  
  248.             strcpy(szDirName,"...\\");
  249.             strcat(szDirName,szTemp);
  250.         }
  251.         SetWindowText(hDirField,szDirName);
  252.  
  253.     }
  254.  
  255.     DWORD DirList::send(WORD msg,WORD wParam,long lParam)
  256.     {
  257.         return SendMessage(hwndChild,msg,wParam,lParam);
  258.     }
  259.  
  260.  
  261.     BOOL DirList::dirClick(void)
  262.     {
  263.         int index;
  264.  
  265.         char szBuffer[MAXPATH];
  266.  
  267.         if (LB_ERR ==    (index= (WORD) send(LB_GETCURSEL,0,0L)) )
  268.                 return FALSE;
  269.  
  270.         send(LB_GETTEXT,index,(LONG) (char far *) szBuffer);
  271.  
  272.         if (strstr(szBuffer,"[-") != 0)
  273.         {
  274.             setdisk((int) (szBuffer[2]) -  'a');
  275.         }
  276.  
  277.         else
  278.         {
  279.             szBuffer[strlen(szBuffer)-1] = '\0';
  280.             chdir(szBuffer+1);
  281.         }
  282.  
  283.         getcwd(szDirName,MAXPATH);
  284.         reset();
  285.  
  286.         if (strlen(szDirName) > WIDTHDIRFIELD)
  287.         {
  288.             strcpy(szBuffer,szDirName);
  289.             do
  290.                 strcpy(szBuffer,(char *)strchr(szBuffer,'\\')+1);
  291.             while (strlen(szBuffer)>WIDTHDIRFIELD-4);
  292.  
  293.             strcpy(szDirName,"...\\");
  294.             strcat(szDirName,szBuffer);
  295.         }
  296.         SetWindowText(hDirField,szDirName);
  297.  
  298.  
  299.         return TRUE;
  300.     }
  301.  
  302.     void DirList::reset(void)
  303.     {
  304.         send(LB_RESETCONTENT,0,0L);
  305.         send(LB_DIR,0xc010,(LONG)(LPSTR) "*.*");
  306.     }
  307.  
  308. /*---------------------------------------------------------------
  309. FileFinder code
  310. -------------------------------------------------------------*/
  311.  
  312.     void FileFinder::create(HWND hParent)
  313.     {
  314.         HDC hdc;
  315.         TEXTMETRIC tm;
  316.         int cxChar,cyChar;
  317.  
  318.         hdc=GetDC(hParent);
  319.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  320.         GetTextMetrics(hdc,&tm);
  321.         cxChar=tm.tmAveCharWidth;
  322.         cyChar=tm.tmHeight;
  323.         ReleaseDC(hParent,hdc);
  324.  
  325.         FileList::create(hParent);
  326.         DirList::create(hParent);
  327.  
  328.  
  329.     }
  330.  
  331.     void FileFinder::reset(void)
  332.     {
  333.         FileList::reset();
  334.         DirList::reset();
  335.     }
  336.  
  337.     BOOL FileFinder::dirClick()
  338.     {
  339.         BOOL i;
  340.         i=DirList::dirClick();
  341.         FileList::reset();
  342.         return i;
  343.     }
  344.  
  345.     void FileFinder::send(void)
  346.     {
  347.     }
  348.